ct_p_progression <-
  function(crosstab, matsch, other="all", graph_type="lines", legend=FALSE, savePDF=FALSE,...){ 
  
  allst <- vector("list", 34)                           
  allst[[34]] <- crosstab                               
  
  for (i in 34:2){                                      
   
    allst[[i-1]] <- allst[[i]]                              
    
    spieltag <- matsch[matsch[,1]==i, ]               
    
    
    for (j in 1:nrow(spieltag)){                      
      
      heim <- as.character(spieltag[j,2])         
      gast <- as.character(spieltag[j,3])
      
      allst[[i-1]][[heim, gast]] <- NA 
      
    }                                   
  }
  
  club_name <- rownames(crosstab)
  tabelle_st <- data.frame(matrix(ncol=length(allst)+1, nrow=nrow(crosstab)))
  
  for (i in 1:ncol(tabelle_st)-1) {  
    
    colnames(tabelle_st)[1] <- "club"                         
    colnames(tabelle_st)[i+1] <- paste("spieltag", i, sep="")
    
  }                         
  
  tabelle_st$club <- club_name
  
  rank_tab  <- lapply(X=allst,FUN=ct_table)                     
  
  
  for (i in 1:length(allst)) {
    
    
    for (j in 1:nrow(tabelle_st)){                              
      
      
      platzierung <- as.character(rank_tab[[i]][j,1])
      
      zeile <- which(tabelle_st[,1]==platzierung)
      
      tabelle_st[zeile, i+1] <- which(rank_tab[[i]][,1]==platzierung)
      
    } 
    
  }
  
  ifelse("all" %in% other, tmp <- "yes", tmp <- "no")       
  
  if (tmp=="yes"){
    
    tabelle_mod <- tabelle_st  
    
  } 
  
  if (tmp=="no"){                                                                
    
    gleich <- which(tabelle_st[,1] %in% other)    
    
    tabelle_mod <- tabelle_st[gleich,]
    
    w <- c(integer(0))
    
    if(identical(gleich, w)==TRUE)  {                                            
      
      stop("please provide only club names identical to those in crosstab")
    }
    
  }
   
  if (savePDF != FALSE) {
    
    pdf(savePDF, width = 12, height = 11, paper = 'a4r', pointsize = 8)
    
  }
  
  if (legend==TRUE){
    
    margin_vec <- c(2.5,1,1,0)
    
  }  else {
    
    margin_vec <- c(0,1,1,8)
    
  }
  
  par(mar=c(5,4,4,2))     
  par( mar=par()$mar+margin_vec )                                                 
  plot(1, 1, xlim=c(2, ncol(tabelle_st)), ylim=c(nrow(tabelle_st),1), type="n",     
       xlab="",                                                                     
       ylab="ranking", xaxt="n",
       yaxt="n", cex.lab=1.5)   
  
  axis(2, at=nrow(tabelle_st):1,
       as.character(nrow(tabelle_st):1), las=2) 
  
  axis(3, at=2:ncol(tabelle_st),
       as.character(1:34), cex.axis=0.5) 
  
  if (legend != TRUE && savePDF == FALSE){                        
    
    axis(4, at=tabelle_mod[,ncol(tabelle_mod)], labels=tabelle_mod[,1], las=1)            
    mgpvec <- c(-40,-4,-5) 
    
  } else { 
    
    if (legend != TRUE && savePDF != FALSE ){                       
      
      axis(4, at=tabelle_mod[,ncol(tabelle_mod)], labels=tabelle_mod[,1], las=1)  
      mgpvec <- c(-52,-4,-5)
      
    } else { 
      
      if (legend==TRUE && savePDF==FALSE){                          
        
        mgpvec <- c(-38,-4,-5)
        
      } else { 
        
        mgpvec <- c(-50,-4,-5)
        
      } 
      
    }
    
  }
  
  title(xlab="matchday",mgp=mgpvec, cex.lab=1.5)                                  
  
  rain <- rainbow(nrow(tabelle_mod)) 
  
  for (i in 1:nrow(tabelle_mod)){                                                     
    
    lines(2:ncol(tabelle_mod),tabelle_mod[i,2:ncol(tabelle_mod)],lwd=2, col=rain[i], ...)
    
    if ( graph_type=="point" ){
      
      points(2:ncol(tabelle_mod),tabelle_mod[i,2:ncol(tabelle_mod)],col=rain[i], lwd=1, ...)    
      
    } 
  }
  
  if (legend==TRUE){
    
    legend(2, 20,legend=tabelle_mod[,1]
           , ncol=4, lty=1, 
           lwd=3, col=rain, cex=0.75, xpd=TRUE )
    
  }
  
  if(savePDF != FALSE) {
    
    dev.off()
    
  }
}